#include "Example_Opengl_Plot_Controller.h"
#include <sxOpenGL_DefaultCameraRenderer.h>
#include <sxOpenGL_DefaultPlotAxesRenderer.h>
#include <sxOpenGL_PickingController.h>
#include <sxPlotController.h>
#include <sxOpenGL_Canvas.h>

using Sx::OpenGL::Graphics::Contexts::OpenGL_Context;
using Sx::QtInterface::QOpenGL_Viewport;
using Sx::Interface::PlotController;
using Sx::OpenGL::Graphics::Objects::Rendering::OpenGL_DefaultCameraRenderer;
using Sx::OpenGL::Graphics::Picking::OpenGL_PickingController;
using Sx::OpenGL::Graphics::Objects::Rendering::OpenGL_DefaultPlotAxesRenderer;
using Sx::OpenGL::Interface::OpenGL_Canvas;

Example_Opengl_Plot_Controller::Example_Opengl_Plot_Controller(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) {
	ui.setupUi(this);

	this->openglContext = std::make_shared<OpenGL_Context>();
	this->openglViewport = new QOpenGL_Viewport(this, this->openglContext, 120u);
	this->openglViewport->setRealtime(false);
	this->openglViewport->enableUserUpdates();

	this->plotController = std::make_shared<PlotController>(this->openglViewport, std::make_shared<OpenGL_Canvas>(this->openglContext), std::make_shared<OpenGL_PickingController>(), std::make_shared<OpenGL_DefaultCameraRenderer>(this->openglContext), std::make_shared<OpenGL_DefaultPlotAxesRenderer>(this->openglContext));
	this->plotController->initialize();

	this->openglViewport->setController(this->plotController);
	this->openglViewport->setClearColor(0.2f, 0.2f, 0.2f);
}

Example_Opengl_Plot_Controller::~Example_Opengl_Plot_Controller() {}

void Example_Opengl_Plot_Controller::resizeEvent(QResizeEvent* e) {
	this->openglViewport->resize(this->width(), this->height());
}
